<?php
namespace Ygcl\Service;
use Think\Model;
class DistrictService extends Model {
	
	private $m;
	
	function __construct(){
		$this->m = D('YgclDistrict');
	}
	
	/**
	 * 获取select options
	 * @return string
	 */
	public function _get_select_options($curid){
		$tree = new \Think\Tree();
		//根据权限获取校区
		if($_SESSION['curUserRole']['xiaoqu'] !== 'all'){
			$map['id'] = array('in',$_SESSION['curUserRole']['xiaoqu']);
		}
		$data = $this->m->where($map)->select();
		foreach ($data as $r) {
			$r['selected'] = $r['id'] == $curid ? 'selected' : '';
			$array[] = $r;
		}
		$str = "<option value='\$id' \$selected>\$spacer \$title</option>";
		$tree->init($array);
		$select_categorys = $tree->get_tree(0, $str);
		return $select_categorys;
	}
	
	public function _create_cache_district(){
		$map['status'] = 1;
		$data = $this->m->where($map)->order('listorder desc,id desc')->select();
		F('Xiaoqu/xiaoqu',$data);
	}
	
   
}